// import axios from "@/api/axios";
import axios from "../../utils/request_news";

// 请求中台数据
const centreHttps = (type, params, header) => {
  let url = "/cispplatform/mobile/MobileWorkPlatformsServlet";
  if (process.env.NODE_ENV === "production") {
    url = process.env.VUE_APP_ZT_API_ROOT + url;
  }
  // 普通请求axios
  if (type == "get") {
    return axios({
      url: url,
      method: type,
      params: params,
      headers: header || {},
    });
  } else {
    return axios({
      url: url,
      method: type,
      data: params,
      headers: header || {},
    });
  }
};

// 请求后端数据
const adminHttps = (type, url, params, header) => {
  let iscPort = sessionStorage.getItem("iscPort");
  if (iscPort) {
    url = "http://127.0.0.1:" + iscPort + url;
  } else {
    if (process.env.NODE_ENV === "production") {
      // url = process.env.VUE_APP_PH_API_ROOT + url;
    }
  }
  // 普通请求axios
  if (type == "get") {
    return axios({
      url: url,
      method: type,
      params: params,
      headers: header || {},
    });
  } else {
    if (
      url.indexOf("/repair/api/repairOrder/updateRepairAreaOrder") > -1 ||
      url.indexOf("/repair/api/virtual/binding") > -1 ||
      url.indexOf("/repair/api/repairCdrPush/query") > -1
    ) {
      return axios({
        url: url,
        method: type,
        params: params,
        headers: header || {},
      });
    } else {
      return axios({
        url: url,
        method: type,
        data: params,
        headers: header || {},
      });
    }
  }
};

// 第三方接口调用
const otherHttps = (type, url, urls, params, header) => {
  return axios({
    url: process.env.NODE_ENV === "production" ? url : urls,
    method: type,
    data: params || {},
    headers: header || {},
  });
};

export default {
  centreHttps,
  adminHttps,
  otherHttps,
};
